package com.ahui.mallchat.common.common.event.listener;

import com.ahui.mallchat.common.common.event.UserRegisterEvent;
import com.ahui.mallchat.common.user.dao.UserDao;
import com.ahui.mallchat.common.user.domain.entity.User;
import com.ahui.mallchat.common.user.domain.enums.IdempotentEnum;
import com.ahui.mallchat.common.user.domain.enums.ItemEnum;
import com.ahui.mallchat.common.user.service.UserBackpackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

/**
 * Author:ahui
 * Description:
 * Date: 2024/7/25 23:01
 */
@Component
public class UserRegisterListener {

    @Autowired
    private UserBackpackService userBackpackService;

    @Autowired
    private UserDao userDao;

    @Async
    @TransactionalEventListener(classes = UserRegisterEvent.class,phase = TransactionPhase.AFTER_COMMIT)
    public void sendCard(UserRegisterEvent event){
        User user = event.getUser();
        //送一张改名卡
        userBackpackService.acquireItem(user.getId(), ItemEnum.MODIFY_NAME_CARD.getId(), IdempotentEnum.UID,user.getId().toString());
    }
}
